﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WMSWebApi.Implement;
using WMSWebApi.Models;

namespace WMSWebApi.Controllers
{
    [Route("api/[controller][action]")]
    [ApiController]
    public class MaterialController : ControllerBase
    {
        ImpMaterials imp = new ImpMaterials();
        /// <summary>
        /// 添加物料
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        [HttpGet]
        public ActionResult<string> Add(MaterialsTable item)
        {
            return imp.Add(item) >= 1 ? "添加成功" : "添加失败";
        }
        /// <summary>
        /// 删除物料
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpDelete]
        public ActionResult<string> Delete(int id)
        {
            return imp.Delete(id) >= 1 ? "删除成功" : "添加删除";
        }
        /// <summary>
        /// 获取物料
        /// </summary>
        /// <param name="name">物料名称</param>
        /// <returns></returns>
        [HttpPost]
        public MaterialsTable Get(string name)
        {
            return imp.Get(name);
        }
        /// <summary>
        /// 获取所有物料
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public IEnumerable<MaterialsTable> GetAll()
        {
            return imp.GetAll();
        }
        /// <summary>
        /// 获取所有物料名称
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public List<string> GetAllName()
        {
           return  imp.GetMaterial();
        }
        /// <summary>
        /// 修改物料
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        [HttpPut]
        public ActionResult<string> Update(MaterialsTable item)
        {
            return imp.Update(item) >= 1 ? "修改成功" : "修改失败";
        }
    }
}
